
import { language as sqlLanguage } from "monaco-editor/esm/vs/basic-languages/sql/sql";
import { language as javaLanguage } from "monaco-editor/esm/vs/basic-languages/java/java";

const { keywords: sqlKeywords } = sqlLanguage;
const { keywords: javaKeywords } = javaLanguage;

export default function registryCompletion(monaco) {
  registerJavascript(monaco)
  registerSql(monaco)
  registerJava(monaco)
}

export function registerJavascript(monaco) {
  monaco.languages.registerCompletionItemProvider('javascript', {
    provideCompletionItems: (model, position) => {
      const word = model.getWordUntilPosition(position);
      const range = {
        startLineNumber: position.lineNumber,
        endLineNumber: position.lineNumber,
        startColumn: word.startColumn,
        endColumn: word.endColumn
      };
      return {
        suggestions: [
          {
            label: 'console',
            kind: monaco.languages.CompletionItemKind.Module,
            insertText: 'console',
            documentation: 'The console object provides access to the browser\'s debugging console.',
            range
          }
          // ...其他建议项
        ]
      };
    }
  })
}

export function registerSql(monaco) {
  monaco.languages.registerCompletionItemProvider("sql", {
    // 触发提示的字符
    triggerCharacters: [...sqlKeywords],
    provideCompletionItems: () => {
      const keywordsSuggests =  sqlKeywords.map((key) => ({
        label: key,// 显示的名称
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: key,// 真实补全的值
      }))
      return {
        suggestions: [...keywordsSuggests]
      }
    }
  })
}

export function registerJava(monaco) {
  monaco.languages.registerCompletionItemProvider("java", {
    // 触发提示的字符
    triggerCharacters: [...javaKeywords],
    provideCompletionItems: () => {
      const keywordsSuggests =  javaKeywords.map((key) => ({
        label: key,// 显示的名称
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: key,// 真实补全的值
      }))
      return {
        suggestions: [...keywordsSuggests]
      }
    }
  })
}